package com.deyuanyun.pic.pig.controller;

import java.io.OutputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.deyuanyun.pic.common.tool.Globals;
import com.deyuanyun.pic.pig.controller.query.QueryListVO;
import com.deyuanyun.pic.pig.controller.vo.PigTaskPointVO;
import com.deyuanyun.pic.pig.controller.vo.PigTaskVO;
import com.deyuanyun.pic.pig.service.CleanPipeLineTrackService;
import com.deyuanyun.pic.settings.service.pipe.PipeLocationService;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.deyuanyun.pic.common.dto.PageJsonBean;
import com.deyuanyun.pic.common.util.PdfHelper;
import com.deyuanyun.pic.common.util.PdfUtils;
import com.deyuanyun.pic.common.util.UploadUtil;
import com.deyuanyun.pic.common.util.ajax.AjaxSupport;
import com.deyuanyun.pic.common.util.web.Asserts;
import com.deyuanyun.pic.pig.mapper.PigTaskMapper;
import com.deyuanyun.pic.pig.service.CleanPipeLineHistoryService;
import com.deyuanyun.pic.settings.service.pipe.PipeLineService;

/**
 * 清管历史管理控制类
 *
 * @author tt
 */
@Controller
@RequestMapping("/pig/cleanPipeLineHistory")
public class CleanPipeLineHistoryController extends PiggingBaseController {
    static Logger logger = Logger.getLogger(CleanPipeLineHistoryController.class);
    @Resource
    private CleanPipeLineHistoryService cleanPipeLineHistoryService;
    @Resource
    private CleanPipeLineTrackService cleanPipeLineTrackService;

    /**
     * 跳转清管历史查询主页
     *
     * @return
     */
    @RequestMapping("/getCleanPipeLineHistoryIndex.html")
    public ModelAndView getCleanPipeLineHistoryIndex() {

        return forword("/cleanPipe/history/historyQuery");
    }

    /**
     * 加载列表数据
     *
     * @param
     */
    @RequestMapping("/getDataList.json")
    @ResponseBody
    @SuppressWarnings("rawtypes")
    public void getDataList(QueryListVO taskVo) {
        PageJsonBean jsonBean = new PageJsonBean();
        List<PigTaskVO> list = cleanPipeLineHistoryService.getCleanPipeLineHistoryIndex(taskVo);
        jsonBean.setList(list);
        AjaxSupport.sendSuccessText("", "yyyy-MM-dd",jsonBean);
    }

    /**
     * 跳转详情页面
     *
     * @param taskId
     * @return
     */
    @RequestMapping("/getHistoryDetail.html")
    public ModelAndView getHistoryDetail(String taskId, ModelMap model) {
        Asserts.assertTrue(!StringUtils.isEmpty(taskId), "没有获取到对应的任务数据");
        model.addAttribute("taskId",taskId);
        return forword("/cleanPipe/history/historyDetail",model);
    }

    /**
     * 得到详情页面数据
     *
     * @param taskId
     * @return
     */
    @RequestMapping("/getHistoryDetailData.json")
    @ResponseBody
    public void getHistoryDetailData(String taskId) {
        Asserts.assertTrue(!StringUtils.isEmpty(taskId), "没有获取到对应的任务数据");
        //任务信息和对应的收发球信息
        Map<String,Object> map = cleanPipeLineTrackService.queryPigById(taskId);
        //任务通过跟踪点列表
        List<PigTaskPointVO> taskPoints =  cleanPipeLineTrackService.queryTaskPoint(taskId,false);
        map.put("taskPoints",taskPoints);
        AjaxSupport.sendSuccessText("","yyyy.MM.dd HH:mm:ss",map);
    }

    /**
     * 评价
     *
     * @param ids
     * @return
     */
    @RequestMapping("/goEvluation.html")
    public ModelAndView goEvluation(String[] ids,ModelMap model) {

        model.addAttribute("ids",ids);
        return forword("/cleanPipe/history/historyEvaluate", model);
    }

    /**
     * 评价
     *
     * @param ids
     * @return
     */
    @RequestMapping("/getEvluation.json")
    @ResponseBody
    public void getEvluation(String[] ids) {
        Map<String, Object> map = new HashMap<String, Object>();
        if (ids.length>0) {
            map = cleanPipeLineHistoryService.goEvluation(ids, map);
        }
       AjaxSupport.sendSuccessText("","yyyy-MM-dd HH:mm:ss",map);
    }



}
